package com.atserver.listener;

import com.atserver.windows.ScannerWindow;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;

/**
 * @program: atserver
 * @Description: 复选框按钮,控制坐标框是否可以输入
 * @author: Mr.Cheng
 * @date: 2022/6/7 3:31 下午
 */
public class CheckBoxChangeListener implements ChangeListener {

    private ScannerWindow window;
    private JCheckBoxMenuItem checkbox;

    public CheckBoxChangeListener() {
    }

    public CheckBoxChangeListener(ScannerWindow window) {
        this.window = window;
    }

    public CheckBoxChangeListener(ScannerWindow window, JCheckBoxMenuItem checkbox) {
        this.window = window;
        this.checkbox = checkbox;
    }

    /**
     * Invoked when the target of the listener has changed its state.
     *
     * @param e a ChangeEvent object
     */
    @Override
    public void stateChanged(ChangeEvent e) {
        if(checkbox.isSelected()){
            window.getXCoordinateTextField().setEnabled(true);
            window.getYCoordinateTextField().setEnabled(true);
        }else {
            window.getXCoordinateTextField().setEnabled(false);
            window.getYCoordinateTextField().setEnabled(false);
        }
    }
}
